name_list=['Tom','Lily','Rose']
print(name_list[0])
print(name_list[1])
print(name_list[2])

print(name_list.index('Lily',0,2))  #1
print(name_list.count('Tom'))   #1
print(len(name_list))  #3

print('Lily' in name_list)    #True
print('Lilys' in name_list)    #False

print('Lily' not in name_list)   #False
print('Lilys' not in name_list)   #True

#例题
name_list1=['Tom','Lily','Rose']
name=input("请输入您的名字：")
if name in name_list1:
    print(f"您输入的名字是{name}，名字已经存在")
else:
    print(f"您输入的名字是{name}.名字不存在")

#增加
name_list.append("zhaoym")
print(name_list)   #['Tom','Lily','Rose','zhaoym']
name_list.append(['xiaoming','xiaohong'])
print(name_list)   #['Tom','Lily','Rose','['xiaoming','xiaohong']']

name_list.extend("liji")
print(name_list)   #['Tom','Lily','Rose','liji']
name_list.extend(['xiaodong','xiaook'])
print(name_list)    #['Tom','Lily','Rose','xiaodong','xiaook']

name_list.insert(1,'xiaoming')
print(name_list)   #['Tom','xiaoming','Lily','Rose']

#删除
# del name_list1
# print(name_list1)

# del name_list1[0]
# # pop():删除指定下标的数据，并返回该数据
# del_name=name_list.pop(1)
# print(del_name)
# print(name_list)
# #remove():移除列表中某个数据的第一个匹配项
# name_list.remove('Rose')
# print(name_list)
# #clear():清空列表
# name_list.clear()
# print(name_list)

#修改
name_list[0]='aaa'
print(name_list)  #['aaa','Lily','Rose']

#逆置reverse()
num_list=[1,5,2,3,6,8]
my_list=['P','y','t','h','o','n']
num_list.reverse()
my_list.reverse()
print(num_list)      #[8,6,5,3,2,1]
print(my_list)

#排序sort()
num_list.sort()
sorted(num_list)
my_list.sort()
print(num_list)   #[1,2,3,5,6,8]
print(my_list)

#复制copy()
name_li2=name_list.copy()
print(name_li2)

#列表的循环遍历
name_list=['Tom','Lily','Rose']
i=0
while i<len(name_list):
    print(name_list[i])
    i+=1

for i in name_list:
    print(i)

name_list = [['⼩小明', '⼩小红', '⼩小绿'], ['Tom', 'Lily', 'Rose'], ['张三', '李李四',
'王五']]
print(name_list[2][1])
